// pages/gift/gift.js
const app = getApp()
var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 500,
    circular: true,
    limit: 20,
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.bannerList();
    this.cards();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //我的礼品卡
  myGift: function () {
    wx.navigateTo({
      url: '../myGift/myGift'
    })
  },

  bannerList: function () {
    var params = new Object();
    params.type = 1;
    var that = this;
    api.POST({
      params: params,
      url: app.globalData.base_url + 'user/banner',
      success: function (res) {
        wx.hideLoading()
        if (util.isEmpty(res.data.code)) {
          if (res.data.data.lenght > 1) {
            var indicatorDots = true
          } else {
            var indicatorDots = false
          }
          that.setData({
            bannerList: res.data.data,
            indicatorDots: indicatorDots
          })
        }
      },
      fail: function (fail) {
        wx.hideLoading()
        util.showError("登录失败，请检查网络");

      }
    })
  },
  cards: function () {
    var that = this;
    api.POST({
      params: {
        limit: that.data.limit,
        page: that.data.page
      },
      url: app.globalData.base_url + 'giftcard/list',
      success: function (res) {
        wx.hideLoading()
        if (res.data.data.list.length > 1) {
          that.setData({
            cardsList: res.data.data.list
          })
        }
      },
      fail: function (fail) {
        wx.hideLoading()
        util.showError("登录失败，请检查网络");
      }
    })
  },

  giftSel: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../giftSel/giftSel?id=' + id,
    })
  }
})